/**
 * ExportExcelResultListener.java	  V1.0   Feb 29, 2012 10:06:52 PM
 *
 * Copyright 2011 AsiaInfo Linkage, All rights reserved.
 *
 * Modification history(By    Time    Reason):
 * 
 * Description:
 */

package xframe.core.interceptor;

import java.io.InputStream;

import xframe.core.utils.CoreConstants;
import xframe.core.utils.FlexiGridJsonToFile;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.PreResultListener;


/**
 * 功能描述：Excel导出，在之前的处理
 *
 * @author  余根宁
 *
 * <p>修改历史：(修改人，修改时间，修改原因/内容)</p>
 */
public class ExportExcelResultListener implements PreResultListener {
    
    private String actionType = "";
    
    private String colModel = "";
    
    /**
     * 
     * 构造函数：
     *
     * @param actionType
     * @param colModel
     */
    public ExportExcelResultListener(String actionType,String colModel){
        this.actionType = actionType;
        this.colModel = colModel;
    }
    
    /* (non-Javadoc)
     * @see com.opensymphony.xwork2.interceptor.PreResultListener#beforeResult(com.opensymphony.xwork2.ActionInvocation, java.lang.String)
     */
    public void beforeResult(ActionInvocation arg0, String arg1) {
        //如果是下载；
        if(CoreConstants.FlexiGridDown.equalsIgnoreCase(this.actionType)){
            //转入下载处理；
            //获取下载的信息；
            String jsonString = arg0.getStack().findString(CoreConstants.FlexiGridJsonString);
            //生成下载信息
            InputStream inputStream = FlexiGridJsonToFile.flexGrid2Excel(jsonString, this.colModel);
            //写入ValueStack;
            arg0.getStack().set(CoreConstants.FlexiGridStream, inputStream);
            arg0.setResultCode(CoreConstants.FlexiGridDownResult);
        }
    }
    
}
